import Vue from 'vue'
import Vuex from 'vuex'
import { getuserAPI } from '@/api/index'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userinfo: {}
    // localStorage.getItem('tokenId')
  },
  getters: {
    username: state => state.userinfo.username,
    nickname: state => state.userinfo.nickname,
    user_pic: state => state.userinfo.user_pic
  },
  mutations: {
    updataToken (state, val) {
      state.token = val
      // localStorage.setItem('tokenId', val)
    },
    updateInfo (state, val) {
      state.userinfo = val
    }
  },
  actions: {
    async getUserInfoAction (store) {
      const res = await getuserAPI()
      console.log(res)
      store.commit('updateInfo', res.data.data)
    }
  },
  modules: {
  },
  plugins: [
    createPersistedState()
  ]
})
